/**
 * Copyright 2009-2020 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.taketoday.jdbc.type;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author Clinton Begin
 * @author TODAY
 */
public interface TypeHandler<T> {

  void setParameter(PreparedStatement ps, int parameterIndex, T parameter) throws SQLException;

  /**
   * Gets the result.
   *
   * @param rs
   *         the rs
   * @param columnName
   *         Colunm name, when configuration <code>useColumnLabel</code> is <code>false</code>
   *
   * @return the result
   *
   * @throws SQLException
   *         the SQL exception
   */
  T getResult(ResultSet rs, String columnName) throws SQLException;

  /**
   * @param rs
   *         ResultSet
   * @param columnIndex
   *         the first column is 1, the second is 2, ...
   *
   * @throws SQLException
   *         if a database access error occurs or this method is
   *         called on a closed result set
   */
  T getResult(ResultSet rs, int columnIndex) throws SQLException;

  T getResult(CallableStatement cs, int columnIndex) throws SQLException;

}
